 <!--
* description: 维修企业注册
* author: chenjingwen
* createdDate: 2021-3-2
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-form-fields="formField"
    />
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import api from '@/api/se/electronicarchives'
import Vue from 'vue'

export default {
  name: 'Maintenancenterprises',

  components: {
    OneTableTemplate
  },

  // 组件混入对象：{data[listQuery] methods[queryTable]}
  mixins: [oneTableWithViewTemplateMixins],

  props: {
    customObj: { type: Object, default: () => { return {} } }
  },

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ''], function() {
      next()
    })
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])

    return {
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          size: 'small',
          name: 'confirm',
          clickEvent: () => this.submit(),
          text: '提交',
          position: 'right'
        }
      ],
      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            {
              compKey: 'compKey1',
              labelName: '门店编码：',
              codeField: 'dlrCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span:8
            },
            {
              compKey: 'compKey2',
              labelName: '门店名称：',
              codeField: 'dlrFullName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true,
              span:8
            },
            {
              compKey: 'compKey8',
              labelName: '道路经营许可证号：',
              codeField: 'companyroadtransportationlicense',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true,
              span:8,
              isRequire:true
            },
            {
              compKey: 'compKey99',
              labelName: '门店Id',
              codeField: 'dlrId',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true,
              span:8,
              isShow:false,
              isRequire:true
            },
            // {
            //   compKey: 'compKey3',
            //   labelName: '门店密码：',
            //   codeField: 'companypassword',
            //   component: () => import('@/components/org/commonInput'),
            //   type: 'inputText',
            //   isMul: false,
            //   isMust: true
            // },
            // {
            //   compKey: 'compKey4',
            //   labelName: '维修企业唯一标识：',
            //   codeField: 'companyunifiedsocialcreditidentifier',
            //   component: () => import('@/components/org/commonInput'),
            //   type: 'inputText',
            //   isMul: false,
            //   isMust: true
            // },
            {
              compKey: 'compKey5',
              labelName: '门店省份：',
              codeField: 'areaCodeProvince',
              oFields: 'areaCodeProvince,areaNameProvince',
              component: () => import('@/components/org/commonSelect'),
              type: 'dropdownList',
              customObj: {
                api: api.queryProvince
              },
              isMul: false,
              isMust: true,
              span:8,
              isRequire:true
            },
            {
              compKey: 'compKey6',
              labelName: '门店城市：',
              codeField: 'areaCodeCity',
              oFields: 'areaCodeCity,areaNameCity',
              parentFileds: 'value:areaCodeProvince-areaCodeProvince',
              component: () => import('@/components/org/commonSelect'),
              type: 'dropdownList',
              customObj: {
                api: api.queryCity,
                listQuery: {
                  areaCodeProvince: ''
                }
              },
              isMul: false,
              isMust: true,
              span:8,
              isRequire:true
            },
            {
              compKey: 'compKey7',
              labelName: '门店区/县：',
              codeField: 'areaCodeCounty',
              oFields: 'areaCodeCounty,areaNameCounty',
              parentFileds: 'value:areaCodeCity-areaCodeCity',
              component: () => import('@/components/org/commonSelect'),
              type: 'dropdownList',
              customObj: {
                api: api.queryCounty,
                listQuery: {
                  areaCodeCity: ''
                }
              },
              isMul: false,
              isMust: true,
              span:8,
              isRequire:true
            },
            // {
            //   compKey: 'compKey9',
            //   labelName: '备注：',
            //   codeField: 'remark',
            //   component: () => import('@/components/org/commonInput'),
            //   type: 'inputText',
            //   isMul: false,
            //   isMust: true,
            //   span: 12
            // }
          ],

      formField: this.$utils.getFormField(this, {
        dlrCode: '',
        dlrFullName: '',
        companypassword: '',
        companyunifiedsocialcreditidentifier: '',
        areaCodeProvince: '',
        areaCodeCity: '',
        areaCodeCounty: '',
        companyroadtransportationlicense: '',
        remark: '',
        dlrId:'',
      }, this.$ConfigCache.CacheConfig.cacheData[viewPageCode])
    }
  },

  methods: {
    // 提交
    submit() {
      this.$utils.validataMoth(this, "validpage");
      if (!this.valid) {
        return false
      }
      this.$confirm('确定要提交吗?', '提示', {
        type: 'warning'
      }).then(() => {
        const that = this
        const queryObj = {
          apiConfig: api.insertEnterpriseRegister,
          variables: that.formField
        }
        var paramD = that.$getParams(queryObj)
        that.$requestAPI(paramD).then((response) => {
          if (response.result === '1') {
            this.$message({
              message: response.msg,
              type: 'success',
              duration: 1000
            })
            this.reset()
          } else {
            this.$message({
              message: response.msg,
              type: 'warn',
              duration: 1000
            })
            this.reset()
          }
        })
      })
    }
  },
  created(){
    // 门店编码
    this.formField.dlrCode=this.$store.getters.orgInfo.DLR_CODE
    // 门店名称
    this.formField.dlrFullName=this.$store.getters.orgInfo.DLR_NAME
    // 门店Id
    this.formField.dlrId=this.$store.getters.orgInfo.DLR_ID
  }
}
</script>
<style lang="scss" scoped>

.filter-params-e3s{

height: 100%;

/deep/.filter-container.filter-params{
  height: 100%;
}

}
/deep/.mixButton .floatDiv-right{
  margin-right: 15px;
}

</style>
